package idiet.dao.hibernate;

import idiet.bean.MealTaste;

import java.util.List;

import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

@Repository("mealTasteDao")
public class MealTasteDao extends BaseDao {
	public MealTaste getMealTasteById(int palId){
		return (MealTaste) this.sessionFactory
				.getCurrentSession()
				.createCriteria(MealTaste.class)
				.add(Restrictions.eq("id", palId))
				.uniqueResult();
	}
	@SuppressWarnings("unchecked")
	public List<MealTaste> getMealTastesByMealTasteName(String mealTasteName){
		return this.sessionFactory
				.getCurrentSession()
				.createCriteria(MealTaste.class)
				.add(Restrictions.like("name",mealTasteName))
				.list();
	}
	@SuppressWarnings("unchecked")
	public List<MealTaste> getMealTastes(){
		return this.sessionFactory
				.getCurrentSession()
				.createCriteria(MealTaste.class)
				.list();
	}
	public void createMealTaste(MealTaste pal){
		this.sessionFactory
		.getCurrentSession()
		.save(pal);
	}
	public void updateMealTaste(MealTaste pal){
		this.sessionFactory
		.getCurrentSession()
		.update(pal);
	}
	public void deleteMealTaste(MealTaste pal){
		this.sessionFactory
		.getCurrentSession()
		.delete(pal);
	}
}
